<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">

      <el-form-item label="公司名称" prop="companyName">
        <el-input
          v-model="queryParams.companyName"
          placeholder="请输入公司名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <!--<el-form-item label="规模" prop="scale">
        <el-input
          v-model="queryParams.scale"
          placeholder="请输入规模"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="customerapplyList" @selection-change="handleSelectionChange">
      <el-table-column fixed type="selection" width="55" align="center"/>
      <el-table-column label="序号" align="center" prop="id"/>
      <el-table-column label="公司名称" align="center" prop="companyName"/>
      <el-table-column label="规模" align="center" prop="scale"/>
      <el-table-column label="联系人" align="center" prop="name"/>

      <el-table-column label="电话号码" align="center" prop="mobile"/>
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column width="150" fixed="right" label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['customerapply:customerapply:edit']"
          >审核
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleDetails(scope.row)"
            v-hasPermi="['customerapply:customerapply:edit']"
          >详情
          </el-button>
        </template>

      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改客户申请对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="入驻审核" prop="status">
          <el-radio-group v-model="form.status">
            <el-radio :label="1">同意</el-radio>
            <el-radio :label="2">拒绝</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="审核原因" prop="remark">
          <el-input type="textarea" v-model="form.remark" placeholder="请输入审核原因"/>
        </el-form-item>
      </el-form>
      <div class="audittext">
        同意会将客户添加到客户线索中，需要在线索中指派一个跟进人进行下一步跟进。拒绝的会直接返回到用户，用户可以再次修改提交
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<style>
  .audittext {
    color: #9e9e9e;
    padding-left: 100px;
  }
</style>
<script>
  import {
    listCustomerapply,
    getCustomerapply,
    delCustomerapply,
    addCustomerapply,
    updateCustomerapply,
    agreeCustomerApply
  } from "@/api/customerapply/customerapply";

  export default {
    name: "Customerapply",
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 客户申请表格数据
        customerapplyList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        status: null,
        remark: "",
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          applyDate: null,
          companyName: null,
          mobile: null,
          name: null,
          scale: null,
          status: null,
          createTime: null,
          updateTime: null,
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
          status: [
            {required: true, message: "审核状态不能为空！", trigger: 'change'}
          ]
        }
      };
    },
    created() {
      this.getList();
    },
    methods: {
      /** 查询客户申请列表 */
      getList() {
        this.loading = true;
        listCustomerapply(this.queryParams).then(response => {
          this.customerapplyList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
      // 详情
      handleDetails(row) {
        this.conductionData.customerapplyDetails = row;
        // console.log(this.conductionData,row)
        this.$router.push({
          path: "/houseapply/CustomerApplyDetails"
        })
      },
      /** 审核按钮操作 */
      handleUpdate(row) {
        /*this.reset();
        const id = row.id || this.ids
        getCustomerapply(id).then(response => {
          this.form = response.data;
          this.open = true;
          this.title = "审核";
        });*/
        this.ids = row.id;
        this.open = true;
        this.title = "审核";
      },
      // 表单重置
      reset() {
        this.form = {
          id: null,
          applyDate: null,
          companyName: null,
          mobile: null,
          name: null,
          remark: null,
          scale: null,
          status: null
        };
        this.resetForm("form");
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            agreeCustomerApply({
              ...this.form,
              id: this.ids
            }).then(response => {
              this.$modal.msgSuccess("操作成功");
              this.open = false;
              this.reset();
              this.getList();
            });
          }
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        this.$modal.confirm('是否确认删除客户申请编号为"' + ids + '"的数据项？').then(function () {
          return delCustomerapply(ids);
        }).then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {
        });
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download('customerapply/customerapply/export', {
          ...this.queryParams
        }, `customerapply_${new Date().getTime()}.xlsx`)
      }
    }
  };
</script>
